<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>商品管理</title> <#include "/WEB-INF/content/module-index.html">
<script type="text/javascript">

$(function(){
	$("#win").window("close");
	$("#search").click(function(){
		var productname=$("#productname").val();
		var orderStatus=$("#status").val();
		var mobile=$("#mobile").val();
		var terminal=$("#terminal").val();
		var spid=$("#spid").val();
		var ptid=$("#ptid").combobox("getValue");
		$("#grid").datagrid("reload",{"productname":productname,"spid":spid,"orderStatus":orderStatus,"ptid":ptid,"mobile":mobile,"terminal":terminal});		
	});	
	$("#btn-save").click(function(){
		$("#win").window("open");
		var oirid=$("#oirid").val();
		var thirdid=$("#thirdid").val();
		var oid=$("#oid").val();
		if(!oirid&&oirid.length==0){
			top.showMsg("请输入第三方流水号");
			return;
		}
		if(!oid&&oid.length==0){
			top.showMsg("请输入第三方流水号");
			return;
		}
		if(!thirdid&&thirdid.length==0){
			top.showMsg("请输入第三方流水号");
			return;
		}
		$.ajax({
			url:moduleUrl.substring(0,moduleUrl.lastIndexOf("/"))+"/confirm",
			type:"POST",
			async:false,
			data:{
				oirid:oirid,
				thirdid:thirdid,
				channels:-1,
				oid:oid
				
			},
			success:function(data){
				$("#win").window("close");
				if(data.state){
					top.showMsg("操作成功");
					$("#grid").datagrid('reload');
				}else{
					top.showMsg("操作失败");
				}
			}
		});
	});
	$("#btn-cancel").click(function(){
		$("#win").window("close");
	});
});

function channelFormatter(value,rowData,rowIndex){
	if(value==0){
		return "票卷";
	}else
		if(value==1){
			return "微信支付";
		}else
			if(value==2){
				return "会员卡支付";
			}else
				if(value==3){
					return "支付宝支付";
				}else
					if(value==4){
						return "银联支付";
					}else
						if(value==5){
							return "道乐支付";
						}else
							return "未知";
}

function statusFormatter(value,rowData,rowIndex){
	if(value==0){
		return "未退款";
	}else
		if(value==1){
			return "已退款";
		}else
			return "未知";
}

function refundFormatter(value,rowData,rowIndex){
	if(rowData.status==0){
		return "<a href='javascript:handler(\""+rowData.oirid+"\","+rowData.channels+",\""+rowData.oid+"\","+rowData.amount+")'>确认退款</a>";
	}
}

function handler(oirid,channels,oid,amount){
	if(channels==5){
		if(confirm("该操作将直接退款至用户道乐账户，是否确认退款?")){
			$.ajax({
				url:moduleUrl.substring(0,moduleUrl.lastIndexOf("/"))+"/confirm",
				type:"POST",
				async:false,
				data:{
					oirid:oirid,
					channels:0,
					amount:amount,
					oid:oid
				},
				success:function(data){
					if(data.state){
						top.showMsg("操作成功");
						$("#grid").datagrid('reload');
					}else{
						top.showMsg("操作失败");
					}
				}
			});
		}
	}else{
		$("#oirid").val(oirid);
		$("#oid").val(oid);
		$("#win").window("open");
	}
}
</script>
<style>
a.btn-border{
	border: 1px solid #ccc;
}
</style>
</head>
<body>
<body class="easyui-layout">
	<div region="center" style="padding: 5px; background:#eee;">
<!-- 		<div id="toolbar">
			<input id="spid" placeholder="订单编号"/>
			<input id="status" placeholder="订单状态"/>
			<input id="productname" placeholder="商品名称"/>
			<input id="mobile" placeholder="手机号码"/>
			<input id="terminal" placeholder="终端"/>
			<input id="parent" placeholder="商品分类">
			<input id="ptid" placeholder="商品分类"/>
			<a id="search" class="easyui-linkbutton" icon="icon-search" style="border: 1px solid #ccc" plain="true">搜索</a>
		</div> -->
		<table id="grid" class="easyui-datagrid" url="query" align="center" idField="oirid" rownumbers="true" striped="true" fitColumns="true" fit="true" pagination="true" singleSelect="true" toolbar="#toolbar">
			<thead>
				<tr>
					<th field="oid" width="20">订单编号</th>
					<th field="tradeNo" width="20">商户交易号</th>
					<th field="amount" width="20">退款金额</th>
					<th field="reason" width="20">退款原因</th>
					<th field="channels" width="30" formatter="channelFormatter">退款渠道</th>
					<th field="createtime" width="20" align='center'>发起时间</th>
					<th field="creator" width="20" align='center'>发起人</th>
					<th field="retrytime" width="20" align='center'>退款时间</th>
					<th field="operator" width="20" align='center'>退款人</th>
					<th field="thirdid" width="20">第三方流水号</th>
					<th field="status" width="20" formatter="statusFormatter">退款状态</th>
					<@auth code="order:refund:confirm">
					<th field="handler" width="20" formatter="refundFormatter">操作</th>
					</@auth>
				</tr>
			</thead>
		</table>
		
		<div id="win" class="easyui-window" title="确认退款" style="width:300px;height:200px;" data-options="iconCls:'icon-save',modal:true">
			<input type="hidden" id="oirid" placeholder="请填写第三方流水号" name="oirid"/>
			<input type="hidden" id="oid" name="oid"/>
			<div style="width:100%;text-align:center;margin-top:30px;">
				<input type="text" id="thirdid" placeholder="请填写第三方流水号" name="thirdid"/>
			</div>
			<div style="width:100%;text-align:center;float:left;margin-top:30px;">
				<a id="btn-save" class="easyui-linkbutton" icon="icon-save" style="border: 1px solid #ccc" plain="true">确定</a>
				<a id="btn-cancel" class="easyui-linkbutton" icon="icon-cancel" style="border: 1px solid #ccc;margin-left:10px;" plain="true">取消</a>
			</div>
		</div>
	</div>
</body>
</body>

</html>